/*
========================================================================
 Name        : SingaporeBusServicesListBoxView.h
 Author      : 
 Copyright   : Your copyright notice
 Description : 
========================================================================
*/
#ifndef __TFLQUERY__
#define __TFLQUERY__


#include "HTTPUtils.h"
#include "CActiveHelper.h"
#include <euserhl.h>
#include "ActiveTarget.h"
#include "imageconversion.h"
#include <http.h>
#include <bitmaptransforms.h>
#include <akndialog.h>
#include "ArrivalTimeQuery.h"
#include <es_sock.h>

class CTflSession;

struct CTflQuery : public CArrivalTimeQuery
{
	CONSTRUCTORS_MAY_LEAVE
	typedef scalp::CFunction<void(CTflQuery*, const TDesC8&, const TDesC8&, TServiceRequestStatus, const TDesC&, const TDesC8&, const TDesC8&)> TCallback;
	HBufC8* iServiceName;
	HBufC8* iStationNumber;
	TServiceRequestStatus iRequestStatus;
	RHTTPTransaction iServiceTransaction;	
	CHTTPTransactionTarget* iServiceTransactionTarget;
	LManagedPtr< TCallback > iCallback;
	CTflSession* iSession;
	CTflQuery(CTflSession* aSession, const TDesC8& aServiceName, const TDesC8& aStationNumber, TCallback* aCallback);
	void SubmitL();
	void Cancel();
	~CTflQuery();
};


	
class CTflSession : public CBase, public MActiveHelperCallback<RTimer*>
	{
	
RArray<CTflQuery*> iTflQueries;
friend class CTflQuery;
public:
	// constructors and destructor
	CTflSession();
	static CTflSession* NewL();
	static CTflSession* NewLC();        
	void ConstructL();
	virtual ~CTflSession();
	
	void SubmitTflConnectRequestL(CTflQuery* aQuery);
	void ReceivedTflConnectAnswerL(CTflQuery* aQuery, RHTTPTransaction aTransaction, THTTPEvent aEvent, TInt aLastError, TPtrC8 aBuf);
	TInt TflConnectTransactionError(CTflQuery* aQuery, TInt aError, RHTTPTransaction aTransaction);
	

	RHTTPSession iHTTPSession;
	void SetConnectionInfoL(const RConnection& aConnection, const RSocketServ& aSocketServ);
	void CloseConnectionL();

	LManagedPtr<CDeflateDecompressor> iDeflateDecompressor;
	RTimer iTflConnectTimeoutTimer;
	CActiveHelper<RTimer*>* iTflTimeoutTimerHelper;
	void MActiveHelperCallbackRunL(CActiveHelper<RTimer*>* aActiveHelper, RTimer* aTimer);
	TInt MActiveHelperCallbackRunError(CActiveHelper<RTimer*>* aActiveHelper, RTimer* aTimer, TInt aError);
	void MActiveHelperCallbackDoCancel(CActiveHelper<RTimer*>* aActiveHelper, RTimer* aTimer);
	
	void NotifyConnected();
	
	TInt iTflStatusCode;
	
	void SubmitL(CTflQuery* aQuery);
	void Cancel(CTflQuery* aQuery);
	
	TBool AllRequestsCompleted() const;

	void CancelAllTflRequestsL();
	
	};

#endif // __TFLQUERY__
